home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9542 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++,rb.technical
  4. Subject: Re: Can copy constructor and operator= share code?
  5. Date: Sat, 02 Mar 1996 16:08:56 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4h9rph$1ug@news.halcyon.com>
  8. References: <4h2kcn$40d@rap.SanDiegoCA.ATTGIS.COM>
  9. NNTP-Posting-Host: blv-pm2-ip16.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Have you tried the reverse: have copy ctor call operator=( toCopy )?
  13. Or *this = toCopy?
  14.  
  15.                     --Norm 
  16.  
  17.  
  18. borisb@sd.znet.com (Boris Burtin) wrote:
  19.  
  20. >I have noticed that a copy constructor and operator= perform pretty
  21. >much the same function.  The code I wrote for my class simply copies
  22. >each member variable from one class to the other.
  23.  
  24. >Is there a way for the one of the two functions to call the other, to
  25. >avoid duplicate code?  I have tried calling the copy constructor from
  26. >operator=, but nothing happens.  I've gotten around this problem by
  27. >creating a private Copy() function, which is called by both the copy
  28. >constructor and operator=.  Is there another way?
  29.  
  30. >Thanks,
  31.  
  32. >Boris
  33.  
  34.  
  35.  
  36.  
  37.